package com.ctyon.watchmanager.bean;

import com.ctyon.common.util.DataUtil;

/**
 * CreateDate：19-7-2 on 下午8:08
 * Describe:
 * Coder: lee
 */
public class AlarmBean {

    private String time;
    private int type;
    private int state;
    private String days;
    private String date;

    public AlarmBean(String alarm) {
        if (!DataUtil.isEmptyAnd(alarm)) {
            String[] data = alarm.split("-");
            this.time = data[0].replace("*", ":");
            this.state = Integer.valueOf(data[1]);
            this.type = Integer.valueOf(data[2]);
            if (type == 1) {
                date = "一次";
                days = "";
            } else if (type == 2) {
                date = "每天";
                days = "";
            } else if (type == 3) {
                this.days = data[3];
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < this.days.length(); i++) {
                    char ch = this.days.charAt(i);
                    int s = ch - '0';
                    if (s == 1) {
                        if (builder.length() > 0){
                            builder.append("、");
                        }
                        builder.append("星期");
                        builder.append(getWeek(i + 1));
                    }
                }
                date = builder.toString();
            }
        }
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getDays() {
        return days;
    }

    public void setDays(String days) {
        this.days = days;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(time);
        sb.append("-");
        sb.append(state);
        sb.append("-");
        sb.append(type);
        if (3 == type) {
            sb.append("-");
            sb.append(days);
        }
        return sb.toString();
    }

    private String getWeek(int i){
        if (i == 1){
            return "一";
        } else if (i == 2){
            return "二";
        }else if (i == 3){
            return "三";
        }else if (i == 4){
            return "四";
        }else if (i == 5){
            return "五";
        }else if (i == 6){
            return "六";
        }else if (i == 7){
            return "日";
        }
        return "";
    }
}
